import java.lang.reflect.Field;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/4/24 16:16
 */
public class B {
    public static void main(String[] args) throws IllegalAccessException {
        Class<User> tClass = User.class;
        User user = new User();
        user.setId("id_1");
        user.setAge(10);
        
        
    
        Field[] fields = tClass.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            Object o = field.get(user);
            System.out.println(o);
        }
    }
}

class User{
   private String id;
   private int age;
    
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public int getAge() {
        return age;
    }
    
    public void setAge(int age) {
        this.age = age;
    }
}